var app = getApp()
var QQMapWX = require('../../utils/qqmap-wx-jssdk.js');
Page({
  data: {
    objarr: [],
    height:0,
    width:0,
    currentTab: 0,
    txt:'',
    objarr:[],
    wishid:''
  },
  onLoad: function (options) {
    var that = this;
    
    wx.getSystemInfo({
      success: function (res) {
        console.log(res);
        that.setData({
           width: res.windowWidth,
           height:res.windowHeight })
      }
    })

    app.ajax("product", {}, (data, err) => {
      if(data.data.list.length != 0){
        this.setData({
            objarr:data.data.list,
            currentTab:data.data.list[0].id
        })
      }
      
    })
  },
  gettxetarea(e){
    this.setData({
      txt:e.detail.value
    })
  },
  clickfu(e) {
    let tab = e.currentTarget.dataset.tab
    if (this.data.currentTab != tab) {
      this.setData({
        currentTab: tab,
      })

    }
  },
  submitwish(){
    if (!app.check_empty(this.data.txt)){
      let par = {
        content:this.data.txt,
        product_id:this.data.currentTab
      }
      app.ajax("publish_wish", par, (datas, err) => {
        if(datas.result == "success"){
          let wishid = datas.data.wish_id
          if(datas.data.need_pay){
            
          }else{
            wx.navigateTo({
              url: '/pages/wish/yourwish?from=mine&id='+wishid
            })
          }
        }else if(datas.result == 'pay'){
          let data = {
            appId: datas.appId,
            nonceStr: datas.nonceStr,
            order_no: datas.order_no,
            package: datas.package,
            paySign: datas.paySign,
            signType: datas.signType,
            timeStamp: datas.timeStamp
          }
          let wish_id = datas.wish_id
          app.wxPays({
            data,
            success: function () {
              wx.showToast({
                title: '支付成功哈',
              })
              wx.navigateTo({
                url: '/pages/wish/yourwish?from=mine&id=' + wish_id
              })
            },
            fail: function () {
              wx.showToast({
                title: '支付失败了呢',
              })
            }
          })
        }
      })
    }else{
      wx.showToast({
        title: '内容不能是空',
      })
    }
  }
});